import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		token: "",
		userInfo:{}
	},
	mutations: {
		changeperson(state,type){
			Vue.prototype.$ComFunJS.getStorage('tokenxm').then((res)=>{
				state.userInfo = {...res};
			})
			// Vue.prototype.$ComFunJS.ajax({
			// 	url: "/api/users/info",
			// 	method: 'get',
			// 	success: function(res) {
			// 		if (res.code==200) {
			// 			state.userInfo = {...state.userInfo,...res.data};
			// 			console.log(state.userInfo)
			// 		}
			// 	}
			// })				
		},			
		login(state, provider) {
			let token = provider.token;
			state.hasLogin = true; 
			console.log(state.hasLogin)
			state.token = token;
			Vue.prototype.$ComFunJS.token = token;
			let data = {...provider}
			uni.setStorage({ //缓存用户登陆状态
				key: 'tokenxm',
				data: data
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.token = "";
			state.userInfo = {};
			uni.removeStorage({
				key: 'token'
			});
			Vue.prototype.$ComFunJS.token = "";
		}
	},
	actions: {

	}
})

export default store
